home *** CD-ROM | disk | FTP | other *** search
/ One Click 14 / OneClick14.iso / Ferramentas / Convert XLS to Pdf / xls2pdf_setup.exe / {app} / lib / gs_lev2.ps < prev    next >
Encoding:
Text File  |  2002-10-31  |  26.4 KB  |  798 lines

  1. %    Copyright (C) 1990, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_lev2.ps,v 1.22 2002/10/31 10:26:00 ghostgum Exp $
  14. % Initialization file for Level 2 functions.
  15. % When this is run, systemdict is still writable,
  16. % but (almost) everything defined here goes into level2dict.
  17.  
  18. level2dict begin
  19.  
  20. % ------ System and user parameters ------ %
  21.  
  22. % User parameters must obey save/restore, and must also be maintained
  23. % per-context.  We implement the former, and some of the latter, here
  24. % with PostScript code.  NOTE: our implementation assumes that user
  25. % parameters change only as a result of setuserparams -- that there are
  26. % no user parameters that are ever changed dynamically by the interpreter
  27. % (although the interpreter may adjust the value presented to setuserparams)
  28. %
  29. % There are two types of user parameters: those which are actually
  30. % maintained in the interpreter, and those which exist only at the
  31. % PostScript level.  We maintain the current state of both types in
  32. % a read-only local dictionary named userparams, defined in systemdict.
  33. % In a multi-context system, each context has its own copy of this
  34. % dictionary.  In addition, there is a constant dictionary named
  35. % psuserparams where each key is the name of a user parameter that exists
  36. % only in PostScript and the value is a procedure to check that the value
  37. % is legal: setuserparams uses this for checking the values.
  38. % setuserparams updates userparams explicitly, in addition to setting
  39. % any user parameters in the interpreter; thus we can use userparams
  40. % to reset those parameters after a restore or a context switch.
  41. % NOTE: the name userparams is known to the interpreter, and in fact
  42. % the interpreter creates the userparams dictionary.
  43.  
  44. % Check parameters that are managed at the PostScript level.
  45. /.checkparamtype {        % <newvalue> <type> .checkparamtype <bool>
  46.   exch type eq
  47. } .bind def
  48. /.checksetparams {        % <newdict> <opname> <checkdict>
  49.                 %   .checksetparams <newdict>
  50.   2 index {
  51.         % Stack: newdict opname checkdict key newvalue
  52.     3 copy 3 1 roll .knownget {
  53.       exec not {
  54.     pop pop pop load /typecheck signalerror
  55.       } if
  56.       dup type /stringtype eq {
  57.     dup rcheck not {
  58.       pop pop pop load /invalidaccess signalerror
  59.     } if
  60.       } if
  61.     } {
  62.       pop
  63.     } ifelse pop pop
  64.   } forall pop pop
  65. } .bind def    % not odef, shouldn't reset stacks
  66.  
  67. % currentuser/systemparams creates and returns a dictionary in the
  68. % current VM.  The easiest way to make this work is to copy any composite
  69. % PostScript-level parameters to global VM.  Currently, the only such
  70. % parameters are strings.  In fact, we always copy string parameters,
  71. % so that we can be sure the contents won't be changed.
  72. /.copyparam {            % <value> .copyparam <value'>
  73.   dup type /stringtype eq {
  74.     .currentglobal true .setglobal
  75.     1 index length string exch .setglobal
  76.     copy readonly
  77.   } if
  78. } .bind def
  79.  
  80. % Some user parameters are managed entirely at the PostScript level.
  81. % We take care of that here.
  82. systemdict begin
  83. /psuserparams 48 dict def
  84. /getuserparam {            % <name> getuserparam <value>
  85.   /userparams .systemvar 1 index get exch pop
  86. } odef
  87. % Fill in userparams (created by the interpreter) with current values.
  88. mark .currentuserparams
  89. counttomark 2 idiv {
  90.   userparams 3 1 roll put
  91. } repeat pop
  92. /.definepsuserparam {        % <name> <value> .definepsuserparam -
  93.   psuserparams 3 copy pop
  94.   type cvlit /.checkparamtype cvx 2 packedarray cvx put
  95.   userparams 3 1 roll put
  96. } .bind def
  97. end
  98. /currentuserparams {        % - currentuserparams <dict>
  99.   /userparams .systemvar dup length dict .copydict
  100. } odef
  101. /setuserparams {        % <dict> setuserparams -
  102.     % Check that we will be able to set the PostScript-level
  103.     % user parameters.
  104.   /setuserparams /psuserparams .systemvar .checksetparams
  105.     % Set the C-level user params.  If this succeeds, we know that
  106.     % the password check succeeded.
  107.   dup .setuserparams
  108.     % Now set the PostScript-level params.
  109.     % The interpreter may have adjusted the values of some of the
  110.     % parameters, so we have to read them back.
  111.   dup {
  112.     /userparams .systemvar 2 index known {
  113.       psuserparams 2 index known not {
  114.     pop dup .getuserparam
  115.       } if
  116.       .copyparam
  117.       /userparams .systemvar 3 1 roll .forceput  % userparams is read-only
  118.     } {
  119.       pop pop
  120.     } ifelse
  121.   } forall
  122.     % A context switch might have occurred during the above loop,
  123.     % causing the interpreter-level parameters to be reset.
  124.     % Set them again to the new values.  From here on, we are safe,
  125.     % since a context switch will consult userparams.
  126.   .setuserparams
  127. } .bind odef
  128. % Initialize user parameters managed here.
  129. /JobName () .definepsuserparam
  130.  
  131. % Restore must restore the user parameters.
  132. % (Since userparams is in local VM, save takes care of saving them.)
  133. /restore {        % <save> restore -
  134.   //restore /userparams .systemvar .setuserparams
  135. } .bind odef
  136.  
  137. % The pssystemparams dictionary holds some system parameters that
  138. % are managed entirely at the PostScript level.
  139. systemdict begin
  140. currentdict /pssystemparams known not {
  141.   /pssystemparams 40 dict readonly def
  142. } if
  143. /getsystemparam {        % <name> getsystemparam <value>
  144.   //pssystemparams 1 index .knownget { exch pop } { .getsystemparam } ifelse
  145. } odef
  146. end
  147. /currentsystemparams {        % - currentsystemparams <dict>
  148.   mark .currentsystemparams //pssystemparams { } forall .dicttomark
  149. } odef
  150. /setsystemparams {        % <dict> setsystemparams -
  151.     % Check that we will be able to set the PostScript-level
  152.     % system parameters.
  153.    /SAFETY .systemvar /safe get {
  154.      % SAFER mode disallows some changes
  155.      [ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] {
  156.        2 copy .knownget {
  157.      exch //pssystemparams exch .knownget {
  158.            ne { /setsystemparams /invalidaccess signalerror } if
  159.          } {
  160.            pop
  161.          } ifelse
  162.        } {
  163.          pop
  164.        } ifelse
  165.      } forall
  166.    } if
  167.    /setsystemparams //pssystemparams mark exch {
  168.      type cvlit /.checkparamtype cvx 2 packedarray cvx
  169.    } forall .dicttomark .checksetparams
  170.     % Set the C-level system params.  If this succeeds, we know that
  171.     % the password check succeeded.
  172.    dup .setsystemparams
  173.     % Now set the PostScript-level params.  We must copy local strings
  174.     % into global VM.
  175.    dup
  176.     { //pssystemparams 2 index known
  177.        {        % Stack: key newvalue
  178.      .copyparam
  179.      //pssystemparams 3 1 roll .forceput    % pssystemparams is read-only
  180.        }
  181.        { pop pop
  182.        }
  183.       ifelse
  184.     }
  185.    forall pop
  186. } .bind odef
  187.  
  188. % Initialize the passwords.
  189. % NOTE: the names StartJobPassword and SystemParamsPassword are known to
  190. % the interpreter, and must be bound to noaccess strings.
  191. % The length of these strings must be max_password (iutil2.h) + 1.
  192. /StartJobPassword 65 string noaccess def
  193. /SystemParamsPassword 65 string noaccess def
  194.  
  195. % Redefine cache parameter setting to interact properly with userparams.
  196. /setcachelimit {
  197.   mark /MaxFontItem 2 index .dicttomark setuserparams pop
  198. } .bind odef
  199. /setcacheparams {
  200.     % The MaxFontCache parameter is a system parameter, which we might
  201.     % not be able to set.  Fortunately, this doesn't matter, because
  202.     % system parameters don't have to be synchronized between this code
  203.     % and the VM.
  204.   counttomark 1 add copy setcacheparams
  205.   currentcacheparams    % mark size lower upper
  206.     3 -1 roll pop
  207.     /MinFontCompress 3 1 roll
  208.     /MaxFontItem exch
  209.   .dicttomark setuserparams
  210.   cleartomark
  211. } .bind odef
  212.  
  213. % Add bogus user and system parameters to satisfy badly written PostScript
  214. % programs that incorrectly assume the existence of all the parameters
  215. % listed in Appendix C of the Red Book.  Note that some of these may become
  216. % real parameters later: code near the end of gs_init.ps takes care of
  217. % removing any such parameters from ps{user,system}params.
  218.  
  219. % psuserparams
  220.   /MaxFormItem 100000 .definepsuserparam
  221.   /MaxPatternItem 20000 .definepsuserparam
  222.   /MaxScreenItem 48000 .definepsuserparam
  223.   /MaxUPathItem 5000 .definepsuserparam
  224.  
  225. % File Access Permission parameters
  226.   .currentglobal true .setglobal
  227.   /.checkFilePermitparams {
  228.     type /arraytype eq {
  229.       currentuserparams /LockFilePermissions get {
  230.         5 { pop } repeat /setuserparams /invalidaccess signalerror
  231.       }
  232.       if
  233.     } {
  234.       5 { pop } repeat /setuserparams /typecheck signalerror
  235.     }
  236.     ifelse
  237.     true
  238.   } .bind def
  239. % Initialize the File Permission access control to wide open
  240. % These will only be accessed via current/set userparams.
  241. % Values are a string containing multiple nul terminated path strings
  242.   /PermitFileReading dup [ (*) ] .definepsuserparam
  243.     psuserparams exch /.checkFilePermitparams load put
  244.   /PermitFileWriting dup [ (*) ] .definepsuserparam
  245.     psuserparams exch /.checkFilePermitparams load put
  246.   /PermitFileControl dup [ (*) ] .definepsuserparam
  247.     psuserparams exch /.checkFilePermitparams load put
  248.   .setglobal
  249.  
  250. pssystemparams begin
  251.   /CurDisplayList 0 .forcedef
  252.   /CurFormCache 0 .forcedef
  253.   /CurOutlineCache 0 .forcedef
  254.   /CurPatternCache 0 .forcedef
  255.   /CurUPathCache 0 .forcedef
  256.   /CurScreenStorage 0 .forcedef
  257.   /CurSourceList 0 .forcedef
  258.   /DoPrintErrors false .forcedef
  259.   /MaxDisplayList 140000 .forcedef
  260.   /MaxFormCache 100000 .forcedef
  261.   /MaxOutlineCache 65000 .forcedef
  262.   /MaxPatternCache 100000 .forcedef
  263.   /MaxUPathCache 300000 .forcedef
  264.   /MaxScreenStorage 84000 .forcedef
  265.   /MaxSourceList 25000 .forcedef
  266.   /RamSize 4194304 .forcedef
  267. end
  268.  
  269. % Define the procedures for handling comment scanning.  The names
  270. % %ProcessComment and %ProcessDSCComment are known to the interpreter.
  271. % These procedures take the file and comment string and file as operands.
  272. /.checkprocesscomment {
  273.   dup null eq {
  274.     pop true
  275.   } {
  276.     dup xcheck {
  277.       type dup /arraytype eq exch /packedarraytype eq or
  278.     } {
  279.       pop false
  280.     } ifelse
  281.   } ifelse
  282. } .bind def
  283. /ProcessComment null .definepsuserparam
  284. psuserparams /ProcessComment {.checkprocesscomment} put
  285. (%ProcessComment) cvn {
  286.   /ProcessComment getuserparam
  287.   dup null eq { pop pop pop } { exec } ifelse
  288. } bind def
  289. /ProcessDSCComment null .definepsuserparam
  290. psuserparams /ProcessDSCComment {.checkprocesscomment} put
  291. /.loadingfont false def
  292. (%ProcessDSCComment) cvn {
  293.   /ProcessDSCComment getuserparam
  294.   dup null eq .loadingfont or { pop pop pop } { exec } ifelse
  295. } bind def
  296.  
  297. % ------ Miscellaneous ------ %
  298.  
  299. (<<) cvn            % - << -mark-
  300.   /mark load def
  301. (>>) cvn            % -mark- <key1> <value1> ... >> <dict>
  302.   /.dicttomark load def
  303. /languagelevel 2 def
  304. % When running in Level 2 mode, this interpreter is supposed to be
  305. % compatible with Adobe version 2017.
  306. /version (2017) readonly def
  307.  
  308. % If binary tokens are supported by this interpreter,
  309. % set an appropriate default binary object format.
  310. /setobjectformat where
  311.  { pop
  312.    /RealFormat getsystemparam (IEEE) eq { 1 } { 3 } ifelse
  313.    /ByteOrder getsystemparam { 1 add } if
  314.    setobjectformat
  315.  } if
  316.  
  317. % Aldus Freehand versions 2.x check for the presence of the
  318. % setcolor operator, and if it is missing, substitute a procedure.
  319. % Unfortunately, the procedure takes different parameters from
  320. % the operator.  As a result, files produced by this application
  321. % cause an error if the setcolor operator is actually defined
  322. % and 'bind' is ever used.  Aldus fixed this bug in Freehand 3.0,
  323. % but there are a lot of files created by the older versions
  324. % still floating around.  Therefore, at Adobe's suggestion,
  325. % we implement the following dreadful hack in the 'where' operator:
  326. %      If the key is /setcolor, and
  327. %        there is a dictionary named FreeHandDict, and
  328. %        currentdict is that dictionary,
  329. %      then "where" consults only that dictionary and not any other
  330. %        dictionaries on the dictionary stack.
  331. .wheredict /setcolor {
  332.   /FreeHandDict .where {
  333.     /FreeHandDict get currentdict eq {
  334.       pop currentdict /setcolor known { currentdict true } { false } ifelse
  335.     } {
  336.       .where
  337.     } ifelse
  338.   } {
  339.     .where
  340.   } ifelse
  341. } bind put
  342.  
  343. % ------ Virtual memory ------ %
  344.  
  345. /currentglobal            % - currentglobal <bool>
  346.   /currentshared load def
  347. /gcheck                % <obj> gcheck <bool>
  348.   /scheck load def
  349. /setglobal            % <bool> setglobal -
  350.   /setshared load def
  351. % We can make the global dictionaries very small, because they auto-expand.
  352. /globaldict currentdict /shareddict .knownget not { 4 dict } if def
  353. /GlobalFontDirectory SharedFontDirectory def
  354.  
  355. % VMReclaim and VMThreshold are user parameters.
  356. /setvmthreshold {        % <int> setvmthreshold -
  357.   mark /VMThreshold 2 index .dicttomark setuserparams pop
  358. } odef
  359. /vmreclaim {            % <int> vmreclaim -
  360.   dup 0 gt {
  361.     .vmreclaim
  362.   } {
  363.     mark /VMReclaim 2 index .dicttomark setuserparams pop
  364.   } ifelse
  365. } odef
  366. -1 setvmthreshold
  367.  
  368. % ------ IODevices ------ %
  369.  
  370. /.getdevparams where {
  371.   pop /currentdevparams {    % <iodevice> currentdevparams <dict>
  372.     .getdevparams .dicttomark
  373.   } odef
  374. } if
  375. /.putdevparams where {
  376.   pop /setdevparams {        % <iodevice> <dict> setdevparams -
  377.     mark 1 index { } forall counttomark 2 add index
  378.     .putdevparams pop pop
  379.   } odef
  380. } if
  381.  
  382. % ------ Job control ------ %
  383.  
  384. serverdict begin
  385.  
  386. % We could protect the job information better, but we aren't attempting
  387. % (currently) to protect ourselves against maliciousness.
  388.  
  389. /.jobsave null def        % top-level save object
  390. /.jobsavelevel 0 def        % save depth of job (0 if .jobsave is null,
  391.                 % 1 otherwise)
  392. /.adminjob true def        % status of current unencapsulated job
  393.  
  394. end        % serverdict
  395.  
  396. % Because there may be objects on the e-stack created since the job save,
  397. % we have to clear the e-stack before doing the end-of-job restore.
  398. % We do this by executing a 2 .stop, which is caught by the 2 .stopped
  399. % in .runexec; we leave on the o-stack a procedure to execute aftewards.
  400. %
  401. %**************** The definition of startjob is not complete yet, since
  402. % it doesn't reset stdin/stdout.
  403. /.startnewjob {            % <exit_bool> <password_level>
  404.                 %   .startnewjob -
  405.     serverdict /.jobsave get dup null eq { pop } { restore } ifelse
  406.     exch {
  407.             % Unencapsulated job
  408.       serverdict /.jobsave null put
  409.       serverdict /.jobsavelevel 0 put
  410.       serverdict /.adminjob 3 -1 roll 1 gt put
  411.         % The Adobe documentation doesn't say what happens to the
  412.         % graphics state stack in this case, but an experiment
  413.         % produced results suggesting that a grestoreall occurs.
  414.       grestoreall
  415.     } {
  416.             % Encapsulated job
  417.       pop
  418.       serverdict /.jobsave save put
  419.       serverdict /.jobsavelevel 1 put
  420.     } ifelse
  421.         % Reset the interpreter state.
  422.   clear cleardictstack
  423.   initgraphics
  424.   false setglobal
  425. } bind def
  426. /.startjob {            % <exit_bool> <password> <finish_proc>
  427.                 %   .startjob <ok_bool>
  428.   vmstatus pop pop serverdict /.jobsavelevel get eq
  429.   2 index .checkpassword 0 gt and {
  430.     exch .checkpassword exch count 3 roll count 3 sub { pop } repeat
  431.     cleardictstack
  432.         % Reset the e-stack back to the 2 .stopped in .runexec,
  433.         % passing the finish_proc to be executed afterwards.
  434.     2 .stop
  435.   } {        % Password check failed
  436.     pop pop pop false
  437.   } ifelse
  438. } odef
  439. /startjob {            % <exit_bool> <password> startjob <ok_bool>
  440.     % This is a hack.  We really need some way to indicate explicitly
  441.     % to the interpreter that we are under control of a job server.
  442.   .userdict /quit /stop load put
  443.   { .startnewjob true } .startjob
  444. } odef
  445.  
  446. systemdict begin
  447. /quit {                % - quit -
  448.   //systemdict begin serverdict /.jobsave get null eq
  449.    { end //quit }
  450.    { /quit load /invalidaccess /signalerror load end exec }
  451.   ifelse
  452. } bind odef
  453. end
  454.  
  455. % We would like to define exitserver as a procedure, using the code
  456. % that the Red Book says is equivalent to it.  However, since startjob
  457. % resets the exec stack, we can't do this, because control would never
  458. % proceed past the call on startjob if the exitserver is successful.
  459. % Instead, we need to construct exitserver out of pieces of startjob.
  460.  
  461. serverdict begin
  462.  
  463. /exitserver {            % <password> exitserver -
  464.   true exch { .startnewjob } .startjob not {
  465.     /exitserver /invalidaccess signalerror
  466.   } if
  467. } bind def
  468.  
  469. end        % serverdict
  470.  
  471. % ------ Compatibility ------ %
  472.  
  473. % In Level 2 mode, the following replace the definitions that gs_statd.ps
  474. % installs in statusdict and serverdict.
  475. % Note that statusdict must be allocated in local VM.
  476. % We don't bother with many of these yet.
  477.  
  478. /.dict1 { exch mark 3 1 roll .dicttomark } bind def
  479.  
  480. currentglobal false setglobal 25 dict exch setglobal begin
  481. currentsystemparams
  482.  
  483. % The following do not depend on the presence of setpagedevice.
  484. /buildtime 1 index /BuildTime get def
  485. % Also define /buildtime in systemdict because Adobe does so and some fonts use it as ID
  486. systemdict /buildtime dup load put
  487. /byteorder 1 index /ByteOrder get def
  488. /checkpassword { .checkpassword 0 gt } bind def
  489. dup /DoStartPage known
  490.  { /dostartpage { /DoStartPage getsystemparam } bind def
  491.    /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
  492.  } if
  493. dup /StartupMode known
  494.  { /dosysstart { /StartupMode getsystemparam 0 ne } bind def
  495.    /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
  496.  } if
  497. %****** Setting jobname is supposed to set userparams.JobName, too.
  498. /jobname { /JobName getuserparam } bind def
  499. /jobtimeout { /JobTimeout getuserparam } bind def
  500. /ramsize { /RamSize getsystemparam } bind def
  501. /realformat 1 index /RealFormat get def
  502. dup /PrinterName known
  503.  { /setprintername { /PrinterName .dict1 setsystemparams } bind def
  504.  } if
  505. /printername
  506.  { currentsystemparams /PrinterName .knownget not { () } if exch copy
  507.  } bind def
  508. currentuserparams /WaitTimeout known
  509.  { /waittimeout { /WaitTimeout getuserparam } bind def
  510.  } if
  511.  
  512. % The following do require setpagedevice.
  513. /.setpagedevice where { pop } { (%END PAGEDEVICE) .skipeof } ifelse
  514. /defaulttimeouts
  515.  { currentsystemparams dup
  516.    /JobTimeout .knownget not { 0 } if
  517.    exch /WaitTimeout .knownget not { 0 } if
  518.    currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
  519.  } bind def
  520. /margins
  521.  { currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse
  522.  } bind def
  523. /pagemargin
  524.  { currentpagedevice /PageOffset .knownget { 0 get } { 0 } ifelse
  525.  } bind def
  526. /pageparams
  527.  { currentpagedevice
  528.    dup /Orientation .knownget { 1 and ORIENT1 { 1 xor } if } { 0 } ifelse exch
  529.    dup /PageSize get aload pop 3 index 0 ne { exch } if 3 2 roll
  530.    /PageOffset .knownget { 0 get } { 0 } ifelse 4 -1 roll
  531.  } bind def
  532. /setdefaulttimeouts
  533.  { exch mark /ManualFeedTimeout 3 -1 roll
  534.    /Policies mark /ManualFeedTimeout 1 .dicttomark
  535.    .dicttomark setpagedevice
  536.    /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
  537.  } bind def
  538. /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
  539. /setduplexmode { /Duplex .dict1 setpagedevice } bind def
  540. /setmargins
  541.  { exch 2 array astore /Margins .dict1 setpagedevice
  542.  } bind def
  543. /setpagemargin { 0 2 array astore /PageOffset .dict1 setpagedevice } bind def
  544. /setpageparams
  545.  { mark /PageSize 6 -2 roll
  546.    4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
  547.    /Orientation 5 -1 roll ORIENT1 { 1 xor } if
  548.    /PageOffset counttomark 2 add -1 roll 0 2 array astore
  549.    .dicttomark setpagedevice
  550.  } bind def
  551. /setresolution
  552.  { dup 2 array astore /HWResolution .dict1 setpagedevice
  553.  } bind def
  554. %END PAGEDEVICE
  555.  
  556. % The following are not implemented yet.
  557. %manualfeed
  558. %manualfeedtimeout
  559. %pagecount
  560. %pagestackorder
  561. %setpagestackorder
  562.  
  563. pop        % currentsystemparams
  564.  
  565. % Flag the current dictionary so it will be swapped when we
  566. % change language levels.  (See zmisc2.c for more information.)
  567. /statusdict currentdict def
  568.  
  569. currentdict end
  570. /statusdict exch .forcedef    % statusdict is local, systemdict is global
  571.  
  572. % The following compatibility operators are in systemdict.  They are
  573. % defined here, rather than in gs_init.ps, because they require the
  574. % resource machinery.
  575.  
  576. /devforall {        % <proc> <scratch> devforall -
  577.   exch {
  578.     1 index currentdevparams
  579.     /Type .knownget { /FileSystem eq } { false } ifelse
  580.     { exec } { pop pop } ifelse
  581.   } /exec load 3 packedarray cvx exch
  582.   (*) 3 1 roll /IODevice resourceforall
  583. } odef
  584. /devstatus {        % <(%disk*%)> devstatus <searchable> <writable>
  585.             %   <hasNames> <mounted> <removable> <searchOrder>
  586.             %   <freePages> <size> true
  587.             % <string> devstatus false
  588.   dup length 5 ge {
  589.     dup 0 5 getinterval (%disk) eq {
  590.       dup /IODevice resourcestatus {
  591.     pop pop dup currentdevparams
  592.     dup /Searchable get
  593.     exch dup /Writeable get
  594.     exch dup /HasNames get
  595.     exch dup /Mounted get
  596.     exch dup /Removable get
  597.     exch dup /SearchOrder get
  598.     exch dup /Free get
  599.     exch /LogicalSize get
  600.     9 -1 roll pop true
  601.       } {
  602.     pop false
  603.       } ifelse
  604.     } {
  605.       pop false
  606.     } ifelse
  607.   } {
  608.     pop false
  609.   } ifelse
  610. } odef
  611.  
  612. % ------ Color spaces ------ %
  613.  
  614. % Move setcolorsapce, setcolor, and colorspacedict to level2dict
  615. level2dict /setcolorspace .cspace_util 1 index get put
  616. level2dict /setcolor .cspace_util 1 index get put
  617. level2dict /colorspacedict .cspace_util 1 index get put
  618.  
  619. % Add the level 2 color spaces
  620. % DevicePixel is actually a LanguageLevel 3 feature; it is here for
  621. % historical reasons.
  622. %% Replace 1 (gs_devpxl.ps) 
  623. (gs_devpxl.ps) runlibfile
  624.  
  625. %% Replace 1 (gs_ciecs2.ps)
  626. (gs_ciecs2.ps) runlibfile
  627.  
  628. %% Replace 1 (gs_indxd.ps)
  629. (gs_indxd.ps) runlibfile
  630.  
  631. %% Replace 1 (gs_sepr.ps)
  632. (gs_sepr.ps) runlibfile
  633.  
  634. %% Replace 1 (gs_patrn.ps)
  635. (gs_patrn.ps) runlibfile
  636.  
  637.  
  638.  
  639. % ------ CIE color rendering ------ %
  640.  
  641. % Define findcolorrendering and a default ColorRendering ProcSet.
  642.  
  643. /findcolorrendering {        % <intentname> findcolorrendering
  644.                 %   <crdname> <found>
  645.   /ColorRendering /ProcSet findresource
  646.   1 index .namestring (.) concatstrings
  647.   1 index /GetPageDeviceName get exec .namestring (.) concatstrings
  648.   2 index /GetHalftoneName get exec .namestring
  649.   concatstrings concatstrings
  650.   dup /ColorRendering resourcestatus {
  651.     pop pop exch pop exch pop true
  652.   } {
  653.     pop /GetSubstituteCRD get exec false
  654.   } ifelse
  655. } odef
  656.  
  657. 5 dict dup begin
  658.  
  659. /GetPageDeviceName {        % - GetPageDeviceName <name>
  660.   currentpagedevice dup /PageDeviceName .knownget {
  661.     exch pop dup null eq { pop /none } if
  662.   } {
  663.     pop /none
  664.   } ifelse
  665. } bind def
  666.  
  667. /GetHalftoneName {        % - GetHalftoneName <name>
  668.   currenthalftone /HalftoneName .knownget not { /none } if
  669. } bind def
  670.  
  671. /GetSubstituteCRD {        % <intentname> GetSubstituteCRD <crdname>
  672.   pop /DefaultColorRendering
  673. } bind def
  674.  
  675. end
  676. % The resource machinery hasn't been activated, so just save the ProcSet
  677. % and let .fixresources finish the installation process.
  678. /ColorRendering exch def
  679.  
  680. % Define setcolorrendering.
  681.  
  682. /.colorrenderingtypes 5 dict def
  683.  
  684. /setcolorrendering {        % <crd> setcolorrendering -
  685.   dup /ColorRenderingType get //.colorrenderingtypes exch get exec
  686. } odef
  687.  
  688. /.setcolorrendering1 where { pop } { (%END CRD) .skipeof } ifelse
  689.  
  690. .colorrenderingtypes 1 {
  691.   dup .buildcolorrendering1 .setcolorrendering1
  692. } .bind put
  693.  
  694. % Note: the value 101 in the next line must be the same as the value of
  695. % GX_DEVICE_CRD1_TYPE in gscrdp.h.
  696. .colorrenderingtypes 101 {
  697.   dup .builddevicecolorrendering1 .setdevicecolorrendering1
  698. } .bind put
  699.  
  700. % Initialize the default CIE rendering dictionary.
  701. % The most common CIE files seem to assume the "calibrated RGB color space"
  702. % described on p. 189 of the PostScript Language Reference Manual,
  703. % 2nd Edition; we simply invert this transformation back to RGB.
  704. mark
  705.    /ColorRenderingType 1
  706. % We must make RangePQR and RangeLMN large enough so that values computed by
  707. % the assumed encoding MatrixLMN don't get clamped.
  708.    /RangePQR [0 0.9505 0 1 0 1.0890] readonly
  709. % This TransformPQR implements a relative colorimetric intent by scaling
  710. % the XYZ values relative to the white and black points.
  711.    /TransformPQR
  712.      % The implementations have been moved to C for performance.
  713.      [ { .TransformPQR_scale_WB0 } bind
  714.        { .TransformPQR_scale_WB1 } bind 
  715.        { .TransformPQR_scale_WB2 } bind
  716.      ] readonly
  717.    /RangeLMN [0 0.9505 0 1 0 1.0890] readonly
  718.    /MatrixABC
  719.     [ 3.24063 -0.96893  0.05571
  720.      -1.53721  1.87576 -0.20402
  721.      -0.49863  0.04152  1.05700
  722.     ] readonly
  723.    /EncodeABC [ {0 .max 0.45 exp} bind dup dup] readonly
  724.    /WhitePoint [0.9505 1 1.0890] readonly
  725.     % Some Genoa tests seem to require the presence of BlackPoint.
  726.    /BlackPoint [0 0 0] readonly
  727. .dicttomark setcolorrendering
  728.  
  729. %END CRD
  730.  
  731. % Initialize a CIEBased color space for sRGB.
  732. /CIEsRGB [ /CIEBasedABC
  733.   mark
  734.     /DecodeLMN [ {
  735.       dup 0.03928 le { 12.92321 div } { 0.055 add 1.055 div 2.4 exp } ifelse
  736.     } bind dup dup ] readonly
  737.     /MatrixLMN [
  738.       0.412457 0.212673 0.019334
  739.       0.357576 0.715152 0.119192
  740.       0.180437 0.072175 0.950301
  741.     ] readonly
  742.     /WhitePoint [0.9505 1.0 1.0890] readonly
  743.   .dicttomark readonly
  744. ] readonly def
  745.  
  746. % ------ Painting ------ %
  747.  
  748. % A straightforward definition of execform that doesn't actually
  749. % do any caching.
  750. /.execform1 {
  751.     % This is a separate operator so that the stacks will be restored
  752.     % properly if an error occurs.
  753.   dup /Matrix get concat
  754.   dup /BBox get aload pop
  755.   exch 3 index sub exch 2 index sub rectclip
  756.   dup /PaintProc get
  757.   1 index /Implementation known not {
  758.     1 index dup /Implementation null .forceput readonly pop
  759.   } if
  760.   exec
  761. } .bind odef    % must bind .forceput
  762.  
  763. /.formtypes 5 dict
  764.   dup 1 /.execform1 load put
  765. def
  766.  
  767. /execform {            % <form> execform -
  768.   gsave {
  769.     dup /FormType get //.formtypes exch get exec
  770.   } stopped grestore { stop } if
  771. } odef
  772.  
  773. /.patterntypes 5 dict
  774.   dup 1 /.buildpattern1 load put
  775. def
  776.  
  777. /makepattern {            % <proto_dict> <matrix> makepattern <pattern>
  778.   //.patterntypes 2 index /PatternType get get
  779.   .currentglobal false .setglobal exch
  780.         % Stack: proto matrix global buildproc
  781.   3 index dup length 1 add dict .copydict
  782.   3 index 3 -1 roll exec 3 -1 roll .setglobal
  783.   1 index /Implementation 3 -1 roll put
  784.   readonly exch pop exch pop
  785. } odef
  786.  
  787. /setpattern {            % [<comp1> ...] <pattern> setpattern -
  788.   currentcolorspace 0 get /Pattern ne {
  789.     [ /Pattern currentcolorspace ] setcolorspace
  790.   } if setcolor
  791. } odef
  792.  
  793.  
  794. end                % level2dict
  795.